package com.wushijia.designpatterns.templetemethod;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * description:
 * @author yang
 * @date 2018/1/16 19:55
 */
public class TempleteMethodImpl extends AbstractTempleteMethod{

  @Override
  void primitiveOperation1() {
    System.out.println("实现类中具体实现模板方法1");
  }

  @Override
  void primitiveOperation2() {
    System.out.println("实现类中具体实现模板方法2");
  }

  @Override
  public boolean hook(){
    String answer = getUserInfo();
    if (answer.toLowerCase().startsWith("y")){
      return true;
    }else {
      return false;
    }
  }

  private static String getUserInfo(){
    String answer = null;
    System.out.println("你想要牛奶吗？");
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
    try {
      answer = bufferedReader.readLine();
    } catch (IOException e) {
      System.out.println("输入错误！！！");
      e.printStackTrace();
    }
    if (answer == null){
      return "no";
    }
    return answer;
  }
}
